﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotaHelp.Models;

namespace DotaHelp.Controllers
{
    public class CompetitionController : Controller
    {
        //
        // GET: /Competition/
        DotaModel model = new DotaModel();

        public class ListG
        {
            
            public string author;
            public int rating;
            //public T Object;
            public IEnumerable<Guide> guides;
        }

        public ActionResult List()
        {
            DateTime dBegin = DateTime.Parse("28.05.2012");
            DateTime dEnd = DateTime.Parse("11.06.2012");
            ViewBag.dBegin = dBegin;
            ViewBag.dEnd = dEnd;
            //var authorGaids = model.Guides.Where(c => !c.IsDeleted).Where(g => g.Date >= dBegin && g.Date <= dEnd)
            //    .GroupBy(g => g.Author).OrderByDescending(g => g.Sum(a => a.Rating)).Select(g => new { author = g.Key, r = g.Sum(a => a.Rating) });
            var authorGaids = model.Guides.Where(c => !c.IsDeleted).Where(g => g.Date >= dBegin && g.Date <= dEnd)
                .GroupBy(g => g.Author).OrderByDescending(g => g.Sum(a => a.Rating))
                .Select(g => new ListG { author = g.Key, rating = g.Sum(a => a.Rating), guides = g.Select(a => a) }).ToArray();
            return View(authorGaids);
        }

    }
}
